from scipy.optimize import linprog
import numpy as np
#先想办法计算不同工地距离两个料场的距离。
A_position=np.matrix([5,1])
B_position=np.matrix([2,7])
x_position=np.matrix([1.25,8.75,0.5,5.75,3,7.25])
y_position=np.matrix([1.25,0.75,4.75,5,6.5,7.25])
A_length=np.ones([1,6])
A_length=np.matrix(A_length)
B_length=np.ones([1,6])
B_length=np.matrix(B_length)
distance=np.ones([1,12])
distance=np.matrix(distance)
for i in range(0,6):
    A_length[0,i] = ((A_position[0,0]-x_position[0,i])**2+(A_position[0,1]-y_position[0,i])**2)**0.5
    B_length[0,i] = ((B_position[0,0]-x_position[0,i])**2+(B_position[0,1]-y_position[0,i])**2)**0.5
for i in range(0,6):
    distance[0,i]=A_length[0,i]
    distance[0,i+6]=B_length[0,i]
#现在关于距离的问题已经解决，距离已经储存至两个变量：A_length与B_length中
#总的距离矩阵作为系数已经储存在变量distance中
#下面开始进行目标函数系数矩阵的输入
c = np.array(distance)
#下面输入不等式约束条件
A_ub = np.array([[1,1,1,1,1,1,0,0,0,0,0,0],
                 [0,0,0,0,0,0,1,1,1,1,1,1]])
b_ub = np.array([20,
                 20])
#下面输入等式约束条件
A_eq = np.array([[1,0,0,0,0,0,1,0,0,0,0,0],
                 [0,1,0,0,0,0,0,1,0,0,0,0],
                 [0,0,1,0,0,0,0,0,1,0,0,0],
                 [0,0,0,1,0,0,0,0,0,1,0,0],
                 [0,0,0,0,1,0,0,0,0,0,1,0],
                 [0,0,0,0,0,1,0,0,0,0,0,1]])
b_eq = np.array([3,5,4,7,6,11])
#输入自变量自身的取值范围
x1 = [0, np.inf]
x2 = [0, np.inf]
x3 = [0, np.inf]
x4 = [0, np.inf]
x5 = [0, np.inf]
x6 = [0, np.inf]
x7 = [0, np.inf]
x8 = [0, np.inf]
x9 = [0, np.inf]
x10 = [0, np.inf]
x11 = [0, np.inf]
x12 = [0, np.inf]
#调用函数进行求解
res = linprog(c, A_ub, b_ub, A_eq, b_eq, bounds=(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12))
print(res)



















